package com.xoa.service.party;

import com.xoa.dao.party.SmallScaleSecurityUnitMapper;
import com.xoa.model.party.SmallScaleSecurityUnitWithBLOBs;
import com.xoa.util.ToJson;
import com.xoa.util.common.L;
import com.xoa.util.page.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SmallScaleSecurityUnitService {
    @Autowired
    private SmallScaleSecurityUnitMapper smallScaleSecurityUnitMapper;

    /**
     * 增加
     * @param smallScaleSecurityUnitWithBLOBs
     * @return
     */
    @Transactional
    public ToJson insertSelective(SmallScaleSecurityUnitWithBLOBs smallScaleSecurityUnitWithBLOBs){
        ToJson toJson=new ToJson(1,"error");
        int temp=smallScaleSecurityUnitMapper.insertSelective(smallScaleSecurityUnitWithBLOBs);
        if(temp>0){
            toJson.setFlag(0);
            toJson.setMsg("success");
        }
        return toJson;
    }

    /**
     * 按主键删除
     * @param smallScaleSecurityUnitId
     * @return
     */
    @Transactional
    public ToJson deleteById(int smallScaleSecurityUnitId){
        ToJson toJson=new ToJson(1,"error");
        int temp=smallScaleSecurityUnitMapper.deleteByPrimaryKey(smallScaleSecurityUnitId);
        if(temp>0){
            toJson.setFlag(0);
            toJson.setMsg("success");
        }
        return toJson;
    }

    /**
     * 修改
     * @param smallScaleSecurityUnitWithBLOBs
     * @return
     */
    @Transactional
    public ToJson updateSelectiveById(SmallScaleSecurityUnitWithBLOBs smallScaleSecurityUnitWithBLOBs){
        ToJson toJson=new ToJson(1,"error");
        int temp=smallScaleSecurityUnitMapper.updateByPrimaryKeySelective(smallScaleSecurityUnitWithBLOBs);
        if(temp>0){
            toJson.setFlag(0);
            toJson.setMsg("success");
        }
        return toJson;
    }

    /**
     * 主键查询
     * @param smallScaleSecurityUnitId
     * @return
     */
    @Transactional
    public ToJson selectById(int smallScaleSecurityUnitId){
        ToJson<SmallScaleSecurityUnitWithBLOBs> toJson=new ToJson<SmallScaleSecurityUnitWithBLOBs>(1,"error");
        SmallScaleSecurityUnitWithBLOBs temp=smallScaleSecurityUnitMapper.selectByPrimaryKey(smallScaleSecurityUnitId);
        if(temp!=null){
            toJson.setObject(temp);
            toJson.setFlag(0);
            toJson.setMsg("success");
        }
        return toJson;
    }

    /**
     * 分页条件查询
     * @param page
     * @param pageSize
     * @param useFlag
     * @param smallScaleSecurityUnitWithBLOBs
     * @return
     */
    @Transactional
    public ToJson selectSelective(Integer page, Integer pageSize, boolean useFlag,
                                  SmallScaleSecurityUnitWithBLOBs smallScaleSecurityUnitWithBLOBs){
        ToJson<SmallScaleSecurityUnitWithBLOBs> toJson=new ToJson<>(1,"error");
        try {
            PageParams pageParams = new PageParams();
            pageParams.setPage(page);
            pageParams.setPageSize(pageSize);
            pageParams.setUseFlag(useFlag);
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("page", pageParams);
            map.put("smallScaleSecurityUnitWithBLOBs",smallScaleSecurityUnitWithBLOBs);
            List<SmallScaleSecurityUnitWithBLOBs> templist=smallScaleSecurityUnitMapper.selectSelective(map);
            toJson.setTotleNum(pageParams.getTotal());
            toJson.setObj(templist);
            toJson.setFlag(0);
            toJson.setMsg("success");
        }
        catch (Exception e){
            toJson.setMsg(e.getMessage());
            L.e("PzHouseServiceController selServiceByCond:" + e);
        }
        return toJson;


    }
}
